package gui.dialogs;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import function.ScalarFunction1d;
import gui.freechart.FunctionPlotter;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author max
 */
public class Bound_GUI extends javax.swing.JDialog {

    FunctionPlotter plotter;
    int type;double val;
    int rows = 1;
    ScalarFunction1d sc1 = new ScalarFunction1d() {

            @Override
            public double getValue(double x) {
                return Math.pow(x,3);
            }
        };
  
    
    public Bound_GUI(JFrame parent,boolean modal,int type, double val) {
        super(parent, modal);
         this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        initComponents();
        plotter = new FunctionPlotter();
                plotter.addFunction(sc1, 0, 1., .1, "Rand");
                
                this.type = type;
                this.val = val;
                
               // plotter.addtoPanel(jPanel1);
               // plotter.plot(jPanel1.getWidth(), jPanel1.getHeight());
                
                jTable1.setValueAt(0., 0, 0);
                jTable1.setValueAt(1, 0, 1);
                jTable1.setValueAt(type, 0, 2);
                jTable1.setValueAt(val, 0, 3);
                
                
//                jTable1.setValueAt(0, 0, 0);
//                jTable1.setValueAt(.2, 0, 1);
//                jTable1.setValueAt(.2, 1, 0);
//                jTable1.setValueAt(.4, 1, 1);
//                jTable1.setValueAt(.4, 2, 0);
//                jTable1.setValueAt(.6, 2, 1);
//                jTable1.setValueAt(.6, 3, 0);
//                jTable1.setValueAt(.8, 3, 1);
//                jTable1.setValueAt(.8, 4, 0);
//                jTable1.setValueAt(1, 4, 1);
//                jTable1.setValueAt(type, 0, 2);
//                jTable1.setValueAt(type, 1, 2);
//                jTable1.setValueAt(type, 2, 2);
//                jTable1.setValueAt(type, 3, 2);
//                jTable1.setValueAt(type, 4, 2);
//                jTable1.setValueAt(val, 0, 3);
//                jTable1.setValueAt(val, 1, 3);
//                jTable1.setValueAt(val, 2, 3);
//                jTable1.setValueAt(val, 3, 3);
//                jTable1.setValueAt(val, 4, 3);

        
    }
    
    
    public ArrayList<Double> getvals(){
    
        ArrayList<Double> alv = new ArrayList<>();
         for(int i = 0 ; i < rows; i++) alv.add((Double)jTable1.getValueAt(i, 3));
//alv.add((Double)jTable1.getValueAt(0, 3));
//        alv.add((Double)jTable1.getValueAt(1, 3));
//        alv.add((Double)jTable1.getValueAt(2, 3));
//        alv.add((Double)jTable1.getValueAt(3, 3));
//        alv.add((Double)jTable1.getValueAt(4, 3));
    return alv;
    }
    
        public ArrayList<Integer> gettyps(){
    
        ArrayList<Integer> alv = new ArrayList<>();
        
        for(int i = 0 ; i < rows; i++) alv.add((Integer)jTable1.getValueAt(i, 2));
            
        
//        alv.add((Integer)jTable1.getValueAt(0, 2));
//        alv.add((Integer)jTable1.getValueAt(1, 2));
//        alv.add((Integer)jTable1.getValueAt(2, 2));
//        alv.add((Integer)jTable1.getValueAt(3, 2));
//        alv.add((Integer)jTable1.getValueAt(4, 2));
    return alv;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jButton1.setText("Ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "von", "bis", "typ", "wert"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Double.class, java.lang.Double.class, java.lang.Integer.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setToolTipText("typ: 1=festpot, 2 = flow, 3 = noflow");
        jTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setResizable(false);
        jTable1.getColumnModel().getColumn(1).setResizable(false);

        jLabel1.setText("typ:   1=festpotential, 2=flussrand, 3 = no flow");

        jButton2.setText("+");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 430, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 41, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 325, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jButton1)
                        .add(194, 194, 194))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .add(45, 45, 45)
                        .add(jButton2)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 18, Short.MAX_VALUE)
                .add(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
super.dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        if(rows<5){
            
            if(rows == 4)jButton2.setEnabled(false);
        
     rows++;
     
        for (int i = 0; i < rows; i++) {
            
            jTable1.setValueAt(i/rows, i, 0);
            jTable1.setValueAt((double)(i+1)/(double)rows, i, 1);
            jTable1.setValueAt(type, i, 2);
            jTable1.setValueAt(val, i, 3);
            
        }
        
        }
        
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Bound_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Bound_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Bound_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Bound_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Bound_GUI bg = new Bound_GUI(null, false, 1, 2);
                bg.setVisible(true);
                
                //Bound_GUI gui = new Bound_GUI(1, 12);
                //gui.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
